package com.tywj.lib.net.retrofit.callback

import com.tywj.lib.net.retrofit.request.BaseRequest
import okhttp3.ResponseBody
import retrofit2.Response

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/8
 *     desc   : 网络请求回调基类
 *     version: 1.0.0
 * </pre>
 */
abstract class BaseCallback<T> {

    lateinit var request: BaseRequest<*>

    abstract fun onSuccess(data: T)

    open fun onError(code: Int, message: String) {}

    open fun onComplete() {}

    /**
     * 上传进度
     * @param currentSize 已上传大小，单位byte
     * @param totalSize 总大小，单位byte
     * @param progress 当前进度，0-1
     * @param networkSpeed 网速，byte/s
     */
    open fun uploadProgress(currentSize: Long, totalSize: Long, progress: Float, networkSpeed: Long) {}

    /**
     * 下载进度
     * @param currentSize 已下载大小，单位byte
     * @param totalSize 总大小，单位byte
     * @param progress 当前进度，0-1
     * @param networkSpeed 网速，byte/s
     */
    open fun downloadProgress(currentSize: Long, totalSize: Long, progress: Float, networkSpeed: Long) {}

    abstract fun convertResponse(response: Response<ResponseBody>): T?
}